package xiaopiya.robot.handler.rss.tool;

import java.util.HashMap;
import java.util.Map;

import xiaopiya.robot.handler.rss.ChannelKey;
import xiaopiya.robot.handler.rss.exception.RssContentException;

/**
 * @author Ray (ayufox@gmail.com)
 * @version 0.1
 */
public class RssChannelManager
{
	private Map<ChannelKey, IRssService> channelServices = new HashMap<ChannelKey, IRssService>();

	public void setChannelServices(Map<ChannelKey, IRssService> channelServices)
	{
		this.channelServices = channelServices;
	}

	public boolean hasChannel(ChannelKey channel)
	{
		return this.channelServices.containsKey(channel);
	}

	public RssContent getChangeFromLast(ChannelKey channel)
			throws RssContentException
	{
		IRssService service = this.channelServices.get(channel);
		if (service == null)
		{
			return null;
		} else
		{
			return new RssContent(service.getChannel(), service
					.getChangeFromLast());
		}
	}

	public RssContent getLastGet(ChannelKey channel) throws RssContentException
	{
		IRssService service = this.channelServices.get(channel);
		if (service == null)
		{
			return null;
		} else
		{
			return new RssContent(service.getChannel(), service.getLastGet());
		}
	}
}